clear all
load ParEst_eh0_time0_Mex_nokids ParEst_eh0_time0_Mex_nokids
load trans_time1_age0_eh0_comp0.out
Chute =ParEst_eh0_time0_Mex_nokids;
HandleLo = @Principal_A2_n;

Dij=trans_time1_age0_eh0_comp0'; % Read transition moments

Dnf_1	 =	Dij(1);
Dni_1	 =	Dij(2);
Dfn_1	 =	Dij(3);
Dff_1	 =	0;
Dfi_1	 =	Dij(4);
Din_1	 =	Dij(5);
Dii_1	 =	0;
Dif_1  =	Dij(6);
Dni_df_1 = Dij(7);    % Transitions for spouse 2 (spouse) from not working to informal when spouse 1 (head) loses job in formal sector
Dni_di_1 = Dij(8);    % Transitions for spouse 2 (spouse) from not working to informal when spouse 1 (head) loses job in informal sector
Dnf_2	 =	Dij(9);
Dni_2	 =	Dij(10);
Dfn_2	 =	Dij(11);
Dff_2	 =	0;
Dfi_2	 =	Dij(12);
Din_2	 =	Dij(13);
Dii_2	 =	0;
Dif_2  =	Dij(14);
Dni_df_2 = Dij(15);
Dni_di_2 = Dij(16);
Lower =[Dfn_1,Din_1,Dnf_1,Dni_1,Dfi_1,Dif_1,Dfn_2,Din_2,...
     Dnf_2,Dni_2,Dfi_2,Dif_2,Dni_df_2,Dni_di_2,Dni_df_1,Dni_di_1];
LoBo =zeros(1,24);
LoBo = [Lower, 0.1, 0.1, 0.1, 0.1, -10, -1.5, -10, -10];
HiBo = [.81 .81 .81 .991 .81 .81 .81 .81 .81 .81 .81 .81 .91 .81 .91 .91 10 10 10 10 -4 0 0 0];
%options = optimoptions(@simulannealbnd, ...
 %                    'PlotFcn',{@saplotbestf,@saplottemperature,@saplotf,@saplotbestx,@saplotx},...
  %                    'FunctionTolerance',800,'ReannealInterval',2, ...
   %                  'InitialTemperature', 2*10^4*[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 10 10 10 10 10 60], ...
    %                 'TemperatureFcn', @temperaturefast, 'MaxStallIterations', 4000);
                 options = saoptimset( ...
                     'PlotFcn',{@saplotbestf,@saplottemperature,@saplotf,@saplotbestx,@saplotx},...
                     'TolFun',6000,'ReannealInterval',6, ...
                     'InitialTemperature', 14*10^2*[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 10 10 10 10 6 1.5 10 10], ...
                     'TemperatureFcn', @temperaturefast, 'StallIterLimit', 2000);
[x,fval,exitflag,output]  = simulannealbnd(HandleLo, Chute, LoBo, HiBo, options)
ParEst_eh0_time0_Mex_nokids = x;
save ParEst_eh0_time0_Mex_nokids ParEst_eh0_time0_Mex_nokids
